//Index JavaScript
//settings: {url: null, loginname: null, passwd: null, captcha: null, callback: null}
function QxLogin(settings){
	this.doLogin = function(){
		var g=this, p=settings;
		var loginname = p.loginname.val(), passwd = p.passwd.val();
		if(!loginname || !passwd || !captcha || !(/^[0-9A-Za-z]{4,20}$/).test(loginname)){
			jError("登录信息无效",{
				VerticalPosition : 'top',
				HorizontalPosition : 'center',
				autoHide : true,
				clickOverlay : true,
				TimeShown : 2500
		    });
			return false;
		}
		var qxlogin = "";
		for(var i=0;i<loginname.length;i++){
			qxlogin += loginname.charCodeAt(i).toString(36);
		}
		qxlogin += "d";
		for(var i=0;i<passwd.length;i++){
			qxlogin += passwd.charCodeAt(i).toString(36);
		}
		jQuery.ajax({
			type : "POST",
			url : p.url,
			data: {"captcha": p.captcha.val(), "loginname": "***", "passwd": "***", qxlogin: (new Date()).getTime()},
			dataType: "json",
			beforeSend: function(request){
				request.setRequestHeader("qxlogin", qxlogin);
			},
			success: function(data){
				if(!UiUtil.hasErrors(data)) {
					p.callback(true);
				}else{
					p.callback(false);
				}
			}
		});
	};
}

